package com.hxminer.hxwebs.controller;

import com.hxminer.hxwebs.model.ReUser;
import com.hxminer.hxwebs.model.Result;
import com.hxminer.hxwebs.model.User;
import com.hxminer.hxwebs.service.LoginService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpSession;
import javax.validation.Valid;

/**
 * Author YRG
 * Created by on 2018/5/9.
 * Describe
 */
@RestController
public class LoginController {

//    @Autowired
//    private UserRepository userRepository;
//
//    @Autowired
//    private LoginRepository loginRepository;

    @Autowired
    private LoginService loginService;


    /**
     * 登录验证
     */
    @PostMapping(value = "/hxminer/login", produces = "application/json;charset=UTF-8")
    public Result<User> loginUser(@Valid User user, HttpSession httpSession) throws Exception {
        return loginService.findByUser(user, httpSession);
    }

    /**
     * 注册
     *
     * @param user
     * @param
     * @return
     * @throws Exception
     */
    @PostMapping(value = "/hxminer/register", produces = "application/json;charset=UTF-8")
    public Result<User> registerUser(@Valid User user) throws Exception {
        return loginService.registerByUser(user);
    }


    /**
     * 预登录
     *
     * @param
     * @return
     * @throws Exception
     */
    @PostMapping(value = "/hxminer/prelLogin", produces = "application/json;charset=UTF-8")
    public Result<ReUser> prelLogin(@Valid ReUser reUser) throws Exception {
        return loginService.prelLogin(reUser.getToken());
    }
}






















